import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import axios from 'axios'
import store from './store'
import zhCn from 'element-plus/es/locale/lang/zh-cn' // 引入中文语言包
axios.defaults.baseURL = 'http://localhost:8080' 

const app = createApp(App)

// 全局样式（确保body有正确的高度计算）
const style = document.createElement('style')
style.textContent = `
  body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
  }
  .navbar-padding {
    padding-top: 70px;
    min-height: calc(100vh - 70px);
    box-sizing: border-box;
  }
  @media (max-width: 768px) {
    .navbar-padding {
      padding-top: 60px;
      min-height: calc(100vh - 60px);
    }
  }
`
document.head.appendChild(style)

// 注册Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 路由守卫自动处理padding
router.beforeEach((to, from, next) => {
  if (!to.meta.hideNavbar) {
    document.body.classList.add('navbar-padding')
  } else {
    document.body.classList.remove('navbar-padding')
  }
  next()
})

app.use(createPinia())
app.use(router)
app.mount('#app')
app.use(ElementPlus, { locale: zhCn })